/******************************************************************************
STRICTLY CONFIDENTIAL (!)
COPYRIGHT BY MAX AND JAN PEJS

File:	Filter.cpp
Date:	17.07.2013
Author:	Max Pejs
******************************************************************************/

#include "Filter.h"


Filter::Filter()
{
	
	
}

Filter::Filter(const UInt8 FilterCoeffs[])
{
	for(UInt8 lt = 0; lt < CNT_FILTER_COEFS; lt++)
	{
		this->fCoeff[lt] = FilterCoeffs[lt];
		this->rBuff[lt] = 0;
	}
	this->begin = 0;
}

Filter::~Filter(){}

UInt16 Filter::get()
{
	UInt16 result = 0u;
	UInt8 filtFact = 0u;

	for(UInt8 lt = 0; lt < CNT_FILTER_COEFS; lt++)
	{
		// UInt8 index = (begin + lt) % CNT_FILTER_COEFS;
		result = result + (rBuff[lt] * fCoeff[lt]);
		filtFact +=fCoeff[lt];
	}
	
	result /= filtFact;

	return (UInt16)result;
}

void Filter::add(UInt16 m)
{
	rBuff[begin++] = m;
	begin = begin % CNT_FILTER_COEFS;
}